package com.sgame.smobigame;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FriendAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public FriendAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View friendView = convertView;
		if (convertView == null) {
			friendView = inflater.inflate(R.layout.sgame_friend_item, null);
		}

		ImageView imgAvatarFriend = (ImageView) friendView
				.findViewById(R.id.imgAvatarFriend);
		ImageView imgLastPlay = (ImageView) friendView
				.findViewById(R.id.imgLastPlay);
		TextView tvNameFriend = (TextView) friendView
				.findViewById(R.id.tvNameFriend);
		TextView tvSttFriend = (TextView) friendView
				.findViewById(R.id.tvSttFriend);
		TextView tvLastPlay = (TextView) friendView
				.findViewById(R.id.tvLastPlay);

		HashMap<String, String> friends = new HashMap<String, String>();
		friends = data.get(position);
		
		
		imageLoader.DisplayImage(friends.get(FriendsView.TAG_AvatarFriend),
				imgAvatarFriend);
		imageLoader.DisplayImage(friends.get(FriendsView.TAG_LastPlay),
				imgLastPlay);
		tvNameFriend.setText(friends.get(FriendsView.TAG_NameFriend));
		tvSttFriend.setText(friends.get(FriendsView.TAG_SttFriend));
		tvLastPlay.setText("Last Play");
		return friendView;
	}

	@Override
	public int getCount() {

		return data.size();
	}

	@Override
	public Object getItem(int position) {

		return position;
	}

	@Override
	public long getItemId(int position) {

		return position;
	}
}
